<?php

/**
 * @author Edison P. Quinones Jr
 * @version  1.0.0
 * @copyright 2008
 */

class JumpsitesController extends Zend_Controller_Action
{
	function init()
	{
		$this->initView();
		$this->view->baseUrl = $this->getRequest()->getBaseUrl();
		$webInfoNamespace  = new Zend_Session_Namespace('webInfo');
		$this->view->webInfo = $webInfoNamespace->webInfo;
		//Zend_Loader::loadClass('HeaderLink');
		Zend_Loader::loadClass('Zend_Filter_StripTags');
		Zend_Loader::loadClass('JumpsiteDisplay');
		Zend_Loader::loadClass('Page');
		Zend_Loader::loadClass('Layout');
		Zend_Loader::loadClass('LayoutPartPartGroupWidget');

		$countWords = strlen($_SERVER['REQUEST_URI']);
		if (strpos($_SERVER['REQUEST_URI'], '/', $countWords-1) == true)
		{
			$this->_redirect(substr_replace($_SERVER['REQUEST_URI'], '', $countWords-1));
			//$this->view->testingLang = substr_replace($_SERVER['REQUEST_URI'], '', $countWords-1);
		}
		$this->view->user = Zend_Auth::getInstance()->getIdentity();

		# Links
		$registry = Zend_Registry::getInstance();
		$this->view->links = $registry->get('linksArray');
		# end of links
	}
	function indexAction()
	{
		//Header
		$this->view->keywords = 'Edison, Quinones, Jr';
		$this->view->description = 'This is the philippines international airport';
		$this->view->author = 'Edison P. Quinones Jr.';
		$this->view->robots = 'Index';
		$this->view->title = 'Groupjump. The World on the Web!';

		//Page Located
		$this->view->stringToCompareWithTheLink = 'Jumpsites';
		$this->view->PageContentTitle = 'leftLabel';
	}
	function widgetinfoAction()
	{

	}
	function articlesAction()
	{

	}
	function viewAction()
	{
		$filter = new Zend_Filter_StripTags();
		$jumpsiteId = trim($filter->filter($this->_request->getParam('id')));
		$goto = trim($filter->filter($this->_request->getParam('goto')));

		if($goto == null)
		{
			$goto = "Home";
		}

		$webInfoNamespace  = new Zend_Session_Namespace('webInfo');
		$webInfo = $webInfoNamespace->webInfo;

		$this->view->jumpsiteId = $jumpsiteId;

		#------------ Footer Links-------------------
		$footerLinks = '';
		$registry = Zend_Registry::getInstance();
		$footerLinksArray = $registry->get('linksArray');


		foreach ($footerLinksArray as $key => $val)
		{
			$footerLinks = $footerLinks.'<li><a href="'.$webInfo.$val['linksUrl'].'">'.$val['linkName'].'</a></li>';
		}

		$userLogged = Zend_Auth::getInstance()->getIdentity();
		if(isset($userLogged))
		{
			$footerLinks = $footerLinks.'<li><a href="'.$webInfo.'Jumpstart">My Jumpstart</a></li>';
		}
		#---------- end of footer links-------------------


		$jumpsiteDisplay = new JumpsiteDisplay();
		$this->view->jumpsite = $jumpsiteDisplay->getGroupToDisplay($jumpsiteId);

		#----- get the link tab links and description of the page ------
		$page = new Page();
		$where = 'group_id = '.$jumpsiteId;
		$this->view->tabLinks = $page->fetchAll($where, 'id');
		$where = 'group_id = '.$jumpsiteId.' and url = "'.$goto.'"';
		$tabLinks = $page->fetchRow($where);
		$this->view->description = $tabLinks->desc ;
		//fetchAll($where, $order, $limit, $offset);
		#--- end of getting the tab links -----

		#--- get the layout of the page
		$layout = new Layout();
		$where = 'id = '.$tabLinks->layout_id;
		$jsLayout = $layout->fetchRow($where, 'id');
		$this->view->jsLayout = $jsLayout;
		#--- end of getting the layout of the page

		#-------- Widget display -------
		$layoutPartPartGroupWidget = new LayoutPartPartGroupWidget();
		$testingWidget = $layoutPartPartGroupWidget->getByPageId('35');

		$count=0;
		$headerAdditionalContent = '';

		while($count < 10)
		{
			if (isset($testingWidget[$count]['title']))
			{
				$headerAdditionalContent = $headerAdditionalContent.'var boxTitle'.($count+1).' = \''.$testingWidget[$count]['title'].'\';'."\n";
			}
			else 
			{
				$headerAdditionalContent = $headerAdditionalContent.'var boxTitle'.($count+1).' = \'<p>Vacant widget area</p>\';'."\n";
			}
			if (isset($testingWidget[$count]['title']))
			{
				$headerAdditionalContent = $headerAdditionalContent.'var box'.($count+1).' = \''.$testingWidget[$count]['source_code'].'\';'."\n";
			}
			else 
			{
				$headerAdditionalContent = $headerAdditionalContent.'var box'.($count+1).' = \'<p>Please insert a widget here</p>\';'."\n";
			}
			$count++;
		}
		#--------- end of widget display


		$this->view->headerAdditional = '
			<!-- GC -->
			<script type="text/javascript">
  				var cariton = \'<p>Edison P Quinones</p>\';
  				var footerLink = \'<ul>'.$footerLinks.'</ul>\';
  				'.$headerAdditionalContent.'
			</script>
			<script type="text/javascript" src="'.$webInfo.'extjs/adapter/ext/ext-base.js"></script>
			<script type="text/javascript" src="'.$webInfo.'jscripts/portal/ext-all.js"></script>
			<script type="text/javascript" src="'.$webInfo.'jscripts/portal/Portal.js"></script>
			<script type="text/javascript" src="'.$webInfo.'jscripts/portal/PortalColumn.js"></script>
			<script type="text/javascript" src="'.$webInfo.'jscripts/portal/Ext.ux.MaximizeTool.js"></script>
			<script type="text/javascript" src="'.$webInfo.'jscripts/portal/Portlet.js"></script>
			<script type="text/javascript" src="'.$webInfo.'jscripts/portal/'.$jsLayout->js_file_for_layout.'"></script>
			<script type="text/javascript" src="'.$webInfo.'jscripts/portal/sample-grid.js"></script>
			<link rel="stylesheet" type="text/css" href="'.$webInfo.'css/portal/portal.css" />   
			<link rel="stylesheet" type="text/css" href="'.$webInfo.'css/portal/sample.css" />
			<script type="text/javascript" src="'.$webInfo.'jscripts/portal/tabs.js"></script>
			<!-- ENDLIBS -->
			';



	}
}